﻿Shader "Dan/UI/UI_BarGraph_Line"
{
    Properties
    {
        _Color1 ("Color1", Color) = (0,0.5,1,1)
        _Color2 ("Color2", Color) = (1,0,0,1)
        _Emission ("Emission", Float ) = 1
        _EmissionRamp ("EmissionRamp", Range(0, 1)) = 0.5
        _Density ("Density", Float ) = 64
        _Width ("Width", Range(0, 1)) = 0.5
        _Length ("Length", Range(0, 1)) = 0.75
        _LengthContrast ("LengthContrast", Range(0, 1)) = 0.1
        _Mask ("Mask", Range(0, 1)) = 0.5
        _RandomSpeed ("RandomSpeed", Float ) = 1
        
        
    }
    SubShader
    {
        Tags {  "Queue"="Transparent" "RenderType"="Transparent" }
        LOD 100

        Pass
        {
            
           
            Blend SrcAlpha OneMinusSrcAlpha
            ZWrite Off       
            
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            

            #include "UnityCG.cginc"
            #include "../ShaderLibs/UIFX.cginc"
            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            

             float _Mask;

             float _Width;
             float _Length;
             float _Density;
             float4 _Color1;
             float4 _Color2;
             float _Emission;
             float _EmissionRamp;
             float _RandomSpeed;
             float _LengthContrast;
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
               
                return o;
            }
            
            fixed4 frag (v2f i) : SV_Target
            {
                float2 uv =i.uv;
                float level = _Density+0.5;
                // float gradient = floor(uv.x * level) / (level - 1);//黑白分层渐变
                // //随机值
                // float2 rdVal = float2(gradient,gradient)+(_Time.y*0.001*_RandomSpeed);
                // float2 skew = rdVal + 0.2127+rdVal.x*0.3713*rdVal.y;
                // float2 rnd = 1.789*sin(skew*512.125);
                // //随机闪烁
                // float flicker = uv.y+ frac(rnd.x*rnd.y*(1+skew.x))*_LengthContrast;
                // //柱状 mask
                // float bar =step(flicker,_Length);
                // float maskWidth =step(frac((uv.x*level)),_Width);
                // float maskHeight = step(_Mask,uv.y);
                
                // //剔除
                // clip(saturate(bar*maskWidth*maskHeight) - 0.5);
                BarGraph(uv.y,uv.x,_Density,_RandomSpeed,_LengthContrast,_Length,_Width,_Mask);

                //颜色
                float3 finalColor = lerp(_Color1.rgb,_Color2.rgb,_EmissionRamp*uv.y)*_Emission;
                

                return fixed4(finalColor,1);
            }
            ENDCG
        }
    }
}
